Class TimePicker extends Box
public var hour;
public var minute;
var partList;
var hourList;
var minuteList;
var moveType=0;
var pressY;
var limits;
var limitTime=0;
function TimePicker(hour=12,minute=0,limits=null){
	this.hour=hour;
	this.minute=minute;
	this.limits=limits;
	this.setSize("f",320);
	this.addChild([
		[{pos:[0,120,"f",80],bg:[,["#eee","#eee"]]}],
		[{dim:"partList",pos:[130,0,130,"f"]}],
		[{dim:"hourList",pos:["+",0,130,"f"],bg2:"#4000"}],
		[{dim:"minuteList",pos:["+",0,130,"f"]}],
	]);
	var arr=[[25,22,0.4],[40,24,0.5],[55,30,0.6],[80,34,1],[55,30,0.6],[40,24,0.5],[25,22,0.4]];
	var y=0;
	for(var i=0;i<7;i++){
		var a=arr[i];
		for(var j=0;j<3;j++){
			var box=this.children[j+1];
			var scaleY=a[2]==0.4?0.8:(a[2]==0.5?0.9:1);
			box.addChild([
				[Label,{pos:[0,y,130,a[0]],fontSize:a[1],alpha:a[2],align:"c",scaleY:scaleY,lineH:a[0]}]
			]);
		}
		y+=a[0];
	}
	this.changeSelf();
}
function resetSelf(){
	this.partList.children[2].setText(this.hour<=12?"":"上午");
	this.partList.children[3].setText(this.hour<=12?"上午":"下午");
	this.partList.children[4].setText(this.hour<=12?"下午":"");
	for(var i=0;i<7;i++){
		var n=this.hour+i-3;
		if(n<=0) n+=12;
		if(n>12) n-=12;
		if(n>12) n-=12;
		var label=this.hourList.children[i];
		label.setText(n);
	}
	for(var i=0;i<7;i++){
		var n=this.minute+(i-3)*5;
		if(n<0) n+=60;
		if(n>=60) n-=60;
		var label=this.minuteList.children[i];
		label.setText(n);
	}
}
function onPress(){
	this.moveType=int(G.x/130);
	if(this.moveType>=4) this.moveType=0;
	this.pressY=G.y;
}
function onRelease(){
	this.moveType=0;
}
function onFrame(){
	if(this.moveType>0&&Math.abs(G.y-this.pressY)>20){
		var dir=G.y>this.pressY?1:-1;
		this.pressY=G.y;
		if(this.moveType==1){
			if(this.hour<=12&&dir==-1) this.hour+=12;
			if(this.hour>12&&dir==1) this.hour-=12;
		}
		if(this.moveType==2){
			this.hour-=dir;
			if(this.hour<=0) this.hour+=24;
			if(this.hour>24) this.hour-=24;
		}
		if(this.moveType==3){
			this.minute-=dir*5;
			if(this.minute<0) this.minute+=60;
			if(this.minute>=60) this.minute-=60;
		}
		this.changeSelf();
	}
	if(!G.isPress){
		if(this.limits&&G.now-this.limitTime>50){
			this.limitTime=G.now;
			var hour=this.hour;
			var minute=this.minute;
			if(hour<this.limits[0]){
				hour++;
			}
			if(hour==this.limits[0]&&minute<this.limits[1]){
				minute+=5;
			}
			if(this.limits.length==4&&hour>this.limits[2]){
				hour--;
			}
			if(this.limits.length==4&&hour==this.limits[2]&&minute>this.limits[3]){
				minute-=5;
			}
			if(hour!=this.hour||minute!=this.minute){
				this.hour=hour;
				this.minute=minute;
				this.changeSelf();
			}
		}
	}
}